from django.db import models
import datetime

# Create your models here.
# 房间信息表（记录当前房间状态）
class Room(models.Model):
    # 房间号
    rid = models.CharField(max_length=10,primary_key=True)

    # 是否有人入住  0-无，1-有
    busy = models.IntegerField(default=0)

    # 空调开关状态  0-close,1-open
    onoff = models.IntegerField(default=0)

    # 空调风速档位，有H,M,L三档，默认是M
    mode = models.CharField(max_length=10,null=True)

    # 目标温度，默认是26
    temp = models.IntegerField(null=True)

    # 优惠折扣
    discount = models.FloatField(null=True)

    # 最近一次入住时间
    checkinDate = models.DateTimeField(null=True)

    # 上一次退房时间
    lastCheckoutDate = models.DateTimeField(null=True)

    # 当前入住客户总金额
    totalcost = models.FloatField(default=0.0)

# 用户信息表
class Customer(models.Model):
    # 用户名
    username = models.CharField(max_length=50)

    # 房间号
    rid = models.ForeignKey(Room,on_delete=models.PROTECT)

    # 房间密码
    password = models.CharField(max_length=50)

    # 电话号码
    phonenumber = models.CharField(max_length=20)

    # 用户状态
    state = models.IntegerField()

    # 入住时间
    checkinDate = models.DateTimeField(null=True)

    # 费用折扣
    discount = models.FloatField(default=1.0)

    # 退房时间
    checkoutDate = models.DateTimeField(null=True)

# 房间日志
class RoomLog(models.Model):
    # 房间号
    rid = models.ForeignKey(Room,on_delete=models.PROTECT)

    # 操作时间
    optime = models.DateTimeField()

    # 目标温度
    temp = models.IntegerField(null=True)

    # 目标档位
    mode = models.CharField(max_length=10,null=True)

    # 空调状态  0-close,1-open
    onoff = models.IntegerField()

    # 房间折扣
    discount = models.FloatField(null=True)

# 酒店流水
class waterbill(models.Model):
    # 房间号
    rid = models.ForeignKey(Room, on_delete=models.PROTECT)

    # 更新时间
    time = models.DateTimeField(default=datetime.datetime.now)

    # 房间总金额（包括未退房顾客的当前消费金额）
    money = models.FloatField(default=0.0)
